<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            margin: 0;
        }

        ul {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        a {
            text-decoration: none;
            color: #404040;
        }

        .wrap {
            width: 600px;
            margin: 0 auto;
        }

        .news-list {
            width: 600px;
        }

        .news {
            width: 100%;
            display: flex;
            justify-content: space-between;
            padding: 15px 0;
            border-bottom: 1px solid #999;
        }

        .info {
            display: flex;
            width: 170px;
            justify-content: space-between;
            font-size: 12px;
            color: #888;
        }

        .tips {
            display: flex;
            width: 100px;
            justify-content: space-between;
        }

        .news-list li:nth-child(5) {
            border-bottom: none;
        }

        .pagination {
            display: flex;
            width: 210px;
            text-align: center;
            background-color: rgb(252, 238, 238);
            border-radius: 25px;
            overflow: hidden;
            margin: 0 auto;
            justify-content: center;
        }

        .pagination a {
            width: 30px;
            line-height: 30px;
            color: #404040;
        }

        .pagination a:nth-child(1) {
            transform: rotate(-45deg);
        }

        .next {
            transform: rotate(45deg);
        }

        .pagination a:hover {
            color: rgb(247, 73, 73);
        }

        .news div {
            width: 420px;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <ul class="news-list">
            <!-- <li class="news">
                <a href="javascript:;">
                    <img src="./img/img.png" alt="">
                </a>
                <div>
                    <h3>
                        <a href="javascript:;">18人死伤！韩国一男子纵火后持凶器伤害避险邻居</a>
                    </h3>
                    <div class="info">
                        <span class="tips"><span>纵火</span><span>韩国</span><span>逮捕</span></span>
                        <span class="line"></span> 
                        <span class="time">| &nbsp;&nbsp;1小时前</span>
                    </div>
                </div>
            </li> -->
        </ul>
    </div>
</body>
<script src="./axios.js"></script>
<script src="./jquery-3.5.1.js"></script>
<script>
    axios({
        method: 'get',
        url: 'http://localhost:2345/news'
    }).then(res => {
        let { data: list } = res
        console.log(list);
        let html = ''
        list.forEach(item => {
            let { addTime, content, country, id, imgUrl, title, type } = item
            html += `<li class="news">
                <a href="javascript:;">
                    <img src=".${imgUrl}" alt="">
                </a>
                <div>
                    <h3>
                        <a href="javascript:;" data-id=${id} class="item">${title}</a>
                    </h3>
                    <div class="info">
                        <span class="tips"><span>${type}</span><span>${country}</span><span>${type}</span></span>
                        <span class="line"></span>
                        <span class="time">| &nbsp;&nbsp;${addTime}</span>
                    </div>
                </div>
            </li>`

        })
        $('.news-list').html(html)
    })
    $('.news-list').on('click', '.item', function () {
        let id = $(this).attr('data-id')
        let dataId = window.localStorage.setItem('dataId', id)
        window.location.href='./newdetail.html'
    })
</script>

</html>